<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
	var lastrand = 31029;
	var posX = new Array();
	var posY = new Array();
	var objNum = 0;
	var objIncrement = 100;
	var tick = 0;
	var lasttick = 0;
	var lasttime = new Date().getTime();
	function isCanvasSupported() { 		//http://diveintohtml5.info
		return !!document.createElement('canvas').getContext;
	}
	
	function isCanvas2DContextSupported() {
		if (!isCanvasSupported()) return false;
		return !!document.createElement('canvas').getContext('2d');
	}
	
	function isCanvasWebglContextSupported() {
		if (!isCanvasSupported()) return false;
		try {
			return !!document.createElement('canvas').getContext('experimental-webgl');
		}
		catch(e)
		{
			return false;
		}
	}
	
	function isCanvasTextSupported() {
		if (!isCanvasSupported() || !isCanvas2DContextSupported()) return false;
		return (typeof document.createElement('canvas').getContext('2d').fillText) == 'function';
	}
	
	function randint(minn , maxn) {
		var d = lastrand / 32749;
		lastrand = (25903 * lastrand + 19997) % 32749;
		return parseInt(minn + d * (maxn - minn + 1));
	}
	
	function initBenchmark() {
		for (var i = 0; i < 20000; i++) {
			posX.push(randint(10, 590));
			posY.push(randint(10, 430));
		}
		var ctx = document.getElementById('canvasPerf').getContext('2d');
		ctx.globalAlpha = 0.05;
		ctx.fillStyle = 'lightgreen';
	}
	
	function benchmark() {
		var ctx = document.getElementById('canvasPerf').getContext('2d');
		ctx.clearRect(0, 0, 640, 480);
		for (i = 0; i < objNum; i++) {
			ctx.fillRect(posX[i], posY[i], 40, 40);
		}
		tick++;
		if (tick - lasttick == 10) {
			var ct = new Date().getTime();
			var dt = ct - lasttime;
			lasttime = ct;
			lasttick = tick;
			fps = 10000 / dt;
			objIncrement = Math.abs(fps - 30) * 10;
			document.getElementById('fps').innerHTML = "FPS: " + parseInt(fps);
			if (fps > 30) objNum += objIncrement;
			else if (fps < 30) objNum -= objIncrement;
			document.getElementById('objects').innerHTML = "Objects: " + parseInt(objNum);
		}
		setTimeout(benchmark, 0);
	}
</script>
</head>

<body>
<canvas id="canvasPerf" width="640" height="480" oncontextmenu="return false;" onselectstart="return false;" style="border: 1px solid;">
	<p>Sorry, your browser does not support canvas element.</p>
</canvas>
<div id='fps'>
	FPS: 0
</div>
<div id='objects'>
	Objects: 0
</div>
<script language="javascript">
	document.write('<p>Canvas: ' + isCanvasSupported() + '</p>');
	document.write('<p>Canvas 2D: ' + isCanvas2DContextSupported() + '</p>');
	document.write('<p>Canvas 2D WebGL: ' + isCanvasWebglContextSupported() + '</p>');
	document.write('<p>Canvas 2D Text: ' + isCanvasTextSupported() + '</p>');
	initBenchmark();
	benchmark();
</script>

</body>
</html>
